<template>
	<view>
		<view class="nav">
			 <u-tabs :list="list1" @click="click" :scrollable="false" 
			         :inactiveStyle="inactiveStyle" :activeStyle="activeStyle" :lineWidth="40"
					  :lineColor="color" :current="current"></u-tabs>
		</view>
		<view class="rows p-top100">
			<studyList v-if="current == 0" :pageData="pageData"></studyList>	
			<answerList v-if="current == 1" :pageData="pageData"></answerList>	
			<empty v-if="!pageData.length"></empty>
		</view>
	</view>
</template>

<script>
	import {mapState} from 'vuex';
	import studyList from './components/studyList.vue'
	import answerList from './components/answerList.vue'
	export default {
		components:{
			studyList,
			answerList
		},
		data() {
			return {
				getMore:true,
				list1:[{
					name:'学习'
				},{
					name:'答题'
				}],
				itemStyle:{
					height:'70rpx'
				},
				current:0,
				page:1,
				limit:10,
				pageData:[],
			}
		},
		onLoad() {
			this.myRank();
		},
		methods: {
			myRank(){
				this.$http.post({
					url:'/DisciplineApi/myRank',
					data:{
						page:this.page,
						limit:this.limit,
						token: this.bid
					}
				}).then(res=>{
					if(res.code != 200) return this.$Toast(res.msg);
					const result = res.data || [];
					this.page == 1?this.pageData = result:this.pageData = this.pageData.concat(result);
					if(!result.length) return this.getMore = false;
				})
			},
			getMyRankingList(){
				this.$http.post({
					url:'/SRA_Standup2021/getMyRankingList',
					data:{
						state:1,
						token: this.bid,
						rank:1,
					}
				}).then(res=>{
					if(!res.success) return;
					this.pageData = res.data || [];
				})
			},
			click(e){
				this.current = e.index;
				this.page = 1;
				this.getMore = true;
				if(this.current == 0) return this.myRank();
				if(this.current == 1) return this.getMyRankingList();
			}
		},
		computed:{
			...mapState(['inactiveStyle','activeStyle','color','bid'])
		},
		onReachBottom() {
			if(this.current == 1 || !this.getMore) return;
			this.page++;
			this.myRank();
		},
	}
</script>

<style lang="scss" scoped>
	// #ifdef MP-WEIXIN
	.nav{
		width:100%;
		height: 100rpx;
		padding:0 140rpx;
		position: fixed;
		top:0;
		left:0;
		z-index:100;
		background-color: #ffffff;
	}
	// #endif
	// #ifdef H5
	.nav{
		width:100%;
		height: 100rpx;
		padding:0 140rpx;
		position: fixed;
		top:40px;
		left:0;
		z-index:100;
		background-color: #ffffff;
	}
	// #endif
</style>
